package com.time.sky.controller;

import com.time.sky.entity.HM;
import com.time.sky.mapper.HmMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/HM")
public class HMController {
    @Autowired
    private HmMapper hmMapper;
    @ResponseBody
    @RequestMapping("/select")
    public List<HM> selectHMList(){   return hmMapper.selectHMList(); }
    @RequestMapping("/add")
    public void addHM(HM hm){
        hmMapper.addHM(hm);
    }
    @RequestMapping("/delete/{hid}")
    public void deleteHM(@PathVariable("hid") int hid){
        hmMapper.deleteHM(hid);
    }
    @RequestMapping("/get/{hid}")
    public HM getHMById(@PathVariable("hid") int hid){
        return hmMapper.getHMById(hid);
    }
    @RequestMapping("/update")
    public void updateHM(HM hm){
        hmMapper.updateHM(hm);
    }
    @RequestMapping("/mohu")
    public List<HM> findByName(HM hm){
        return hmMapper.findByName(hm);
    }
    @ResponseBody
    @RequestMapping("/rows")
    public int rows(){
        return hmMapper.getRowCount();
    }
    @RequestMapping("/deleteBatch")
    public void deleteBatch(String ids){
        String[] idArr = ids.split(",");
        List<Integer> idList=new ArrayList<Integer>();
        for(String id : idArr){
            idList.add(Integer.parseInt(id));
        }
        hmMapper.deleteBatch(idList);
    }
}
